class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int n = nums.size();
        int sum = 0;
        int ma = -1e9, ma1 = -1e9;
        int mi = 1e9;
        for (auto x : nums) {
            sum += x;
            if (sum < 0) sum = 0;
            ma = max(ma, sum);
            ma1 = max(ma1, x);
            mi = min(mi, x);

        }
        if (ma1 < 0)return ma1;
        return ma;
    }
};